package com.insnow.knowshare.entity;

import java.util.Date;

public class PostDTO {
    private Long id;
    private String title;
    private String content;
    private String username;
    private Boolean isTop;
    private Boolean isDeleted;
    private Integer status;
    private Date createTime;
    private Date updateTime;

    // getter/setter
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

    public String getTitle() { return title; }
    public void setTitle(String title) { this.title = title; }

    public String getContent() { return content; }
    public void setContent(String content) { this.content = content; }

    public String getUsername() { return username; }
    public void setUsername(String username) { this.username = username; }

    public Boolean getIsTop() { return isTop; }
    public void setIsTop(Boolean isTop) { this.isTop = isTop; }

    public Boolean getIsDeleted() { return isDeleted; }
    public void setIsDeleted(Boolean isDeleted) { this.isDeleted = isDeleted; }

    public Integer getStatus() { return status; }
    public void setStatus(Integer status) { this.status = status; }

    public Date getCreateTime() { return createTime; }
    public void setCreateTime(Date createTime) { this.createTime = createTime; }

    public Date getUpdateTime() { return updateTime; }
    public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; }

    public static PostDTO fromEntity(Post post, String username) {
        PostDTO dto = new PostDTO();
        dto.setId(post.getId());
        dto.setTitle(post.getTitle());
        dto.setContent(post.getContent());
        dto.setUsername(username);
        dto.setIsTop(post.getIsTop());
        dto.setIsDeleted(post.getIsDeleted());
        dto.setStatus(post.getStatus());
        if (post.getCreatedAt() != null) {
            dto.setCreateTime(java.sql.Timestamp.valueOf(post.getCreatedAt()));
        }
        dto.setUpdateTime(post.getUpdateTime());
        return dto;
    }
}
